#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/device.h>


extern struct bus_type mybus;



void	myrelease(struct device *dev)
{
    printk(KERN_EMERG "this is mydevice release\n");
}

struct device mydevice = {
    .init_name = "mydevice",
    .bus = &mybus,              // 所属总线
    .release = myrelease,       // 设备释放回调
    .devt = ((255<<20|0)),      //设备号
};



static int __init mydevice_init(void)
{   
    int ret;
   
    // 注册 设备
    ret = device_register(&mydevice);
    if (ret < 0)
    {
        printk(KERN_EMERG "mydevice_init error!\n");

        return ret;
    }

    printk(KERN_EMERG "mydevice_init OK!\n");
    return 0;
}

static void __exit mydevice_exit(void)
{
    device_unregister(&mydevice);
    printk(KERN_EMERG "mydevice_exit OK!\n");  
}



module_init(mydevice_init);
module_exit(mydevice_exit);

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Treasure1029");

